package com.park.task;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.model.StatisticData;
import com.park.service.HttpUtil;
import com.park.service.StatisticDataService;
import com.park.service.impl.PosChargeDataServiceImpl;


@Component
@Controller
@RequestMapping("/timer")
public class TestTimerController {
	@Autowired
	private StatisticDataService statisticDataService;
	
	private static Log logger = LogFactory.getLog(TestTimerController.class);
	
	//@Scheduled(cron="0 0 9 * * ?")//每天9点执行
	@RequestMapping("/run")
	@ResponseBody
	public void run() throws Exception{
		/*String url="https://chen.iotclouddashboard.com/push/getContent";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		//当前时间
		Date dNow = new Date();
		//昨天时间
		Date dBefore = new Date();
		Calendar cal = Calendar.getInstance();
		//赋值当前时间
		cal.setTime(dNow);
		//设置为前一天时间
		cal.add(Calendar.DAY_OF_MONTH,-1);
		//获取到前一天时间
		dBefore=cal.getTime();
		//格式化前一天
		String defaultStartDate = sdf.format(dBefore);
		//前一天开始时间
		defaultStartDate = defaultStartDate.substring(0,10)+" 00:00:00";
		//前一天结束时间
		String defaultEndDate = defaultStartDate.substring(0,10)+" 23:59:59";
		String username="jbtfds";
		Map<String, Object> argMap = new HashMap<String, Object>();
		if(defaultStartDate!=""&&defaultEndDate!=""){
			StatisticData statisticData = statisticDataService.selectstatisticDataByYestDay(username,sdf.parse(defaultStartDate),sdf.parse(defaultEndDate));
			double chargeMoneySumje=0.0;//总金额
			int totalTimesbs=0;//总订单数

			chargeMoneySumje+=statisticData.getChargeMoneySum();
			totalTimesbs+=statisticData.getTotalTimes();
			SimpleDateFormat sdfdate = new SimpleDateFormat("yyyy-MM-dd");
			defaultEndDate = sdfdate.format(dBefore);
			
			argMap.put("totalOrder",totalTimesbs);//总金额
			argMap.put("totalMoney",chargeMoneySumje);//总订单数
			argMap.put("statisticsTime",defaultEndDate);//统计时间(为前一天)
			HttpUtil.post(url, argMap);
			System.out.println("argMap:"+argMap);
			logger.info("argMap:"+argMap);
		}else{
			argMap.put("status", 1002);
			System.out.println("argMap:"+argMap);
		}*/
	}
}
